<template>
    <div>
        <!-- 顶部滑动区域 -->
        <div id="slider" class="mui-slider ">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item', item.id==0? 'mui-active':'']" v-for="item in categories" :key="item.id" @click="getImgList(item.id)" data-wid="tab-top-subpage-1.html">
                        {{item.title}}
                    </a>
                </div>
            </div>
        </div>

        <!-- 图片列表区域 -->
        <ul class="photo-list">
            <router-link tag="li" v-for="item in imgList" :key="item.id" :to="'/home/photoinfo/'+ item.id">
                <img v-lazy="item.img_url">
                <div class="info">
                    <h3>{{item.title}}</h3>
                    <div class="content">
                        {{item.zhaiyao}}
                    </div>
                </div>
            </router-link>
        </ul>
    </div>
</template>

<script>
    //导入mui
    import mui from '../../lib/mui/js/mui.js'
    //导入 Toast
    import { Toast } from 'mint-ui'

    export default {
        data(){
            return {
                categories:[],
                imgList:[]
            }
        },
        created(){
            this.getImgCategory()
            this.getImgList(0)
        },
        methods:{
            getImgCategory(){
                this.$http.get('api/getimgcategory').then(result => {
                    if(result.body.status == 0){
                        result.body.message.unshift({id:0,title:'全部'})
                        this.categories = result.body.message
                    }else{
                        Toast('请求图片分类失败')
                    }
                })
            },
            getImgList(cateId){
                this.$http.get('api/getimages/' + cateId).then(result => {
                    if(result.body.status == 0){
                        this.imgList = result.body.message
                    }else{
                        Toast('请求图片列表失败')
                    }
                })
            }
        },
        mounted(){
            // 初始化滑动插件
            mui('.mui-scroll-wrapper').scroll({
                deceleration:0.0005
            })
        }
    }
</script>

<style lang="sass" scoped>
   .photo-list{
       padding:10px;
       margin:0;
       list-style:none;
       li{
           background-color:#ccc;
           text-align:center;
           margin-bottom:10px;
           position:relative;

           .info{
               position:absolute;
               bottom:0;
               color:#fff;
               text-align:left;
               background-color:rgba(0,0,0,0.5) !important;
               max-height:84px;
               h3{
                   font-size:14px !important;
               }
               div{
                   font-size:13px;
               }
           }
            img{
                width:100%;
                vertical-align:middle;
            }
           image[lazy=loading] {
                width: 40px;
                height: 300px;
                margin: auto;
            }
       }
   }
</style>
